<template>
  <div >
    <el-container>
      <el-aside :style="asideStyle">
        <navbar :menus="menus" :collapse="isCollapse"></navbar>
      </el-aside>
      <el-container>
        <el-header>
          <svg
            class="icon"
            :class="iconDeg"
            @click="handleCollapse"
            aria-hidden="true"
          >
            <use xlink:href="#icon-xianxingdingwei"></use>
          </svg>
          <!-- <i
            :class="iconDeg"
            class="el-icon-s-fold"
            @click="handleCollapse"
          ></i> -->
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item><a href="/">活动管理</a></el-breadcrumb-item>
            <el-breadcrumb-item>活动列表</el-breadcrumb-item>
            <el-breadcrumb-item>活动详情</el-breadcrumb-item>
          </el-breadcrumb>
          <el-dropdown>
            <span class="el-dropdown-link">
              用户名<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>用户信息</el-dropdown-item>
              <el-dropdown-item>修改密码</el-dropdown-item>
              <el-dropdown-item>修改头像</el-dropdown-item>
              <el-dropdown-item @click.native="handleLogout"
                >注销用户</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main><router-view></router-view></el-main>
        <el-footer>
          Copyright © 2021-2021 小灰科技 版权所有. All rights
          reserved.</el-footer
        >
      </el-container>
    </el-container>
    <el-dialog title="提示" :visible.sync="dialogVisible">
      <span>你确定要注销吗？+v+</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleConfirmLog">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import routes from "../router/routes";
import Navbar from "./Navbar";
import { clearToken } from "../utils/auth"
export default {
  components: {
    Navbar,
  },
  data() {
    return {
      isCollapse: false,
      dialogVisible: false,
    };
  },
  methods: {
    handleLogout() {
      console.log("注销");
      this.dialogVisible = true;
    },
    handleConfirmLog() {
      console.log("确定注销");
      clearToken()
      // localStorage.removeItem("accessToken");
      // localStorage.removeItem("refreshToken");
      this.$router.push('/login')
    },
    resolve(arr, parentPath = "") {
      let newArr = [];
      //第一步遍历数组当中的每一个元素
      arr.forEach((route) => {
        let obj = Object.assign({}, route);

        // 当上级路径存在，并且最后一位不为/，则后面添加 /
        parentPath =
          parentPath && parentPath.lastIndexOf("/") !== parentPath.length - 1
            ? parentPath + "/"
            : parentPath;

        // 总是给加上父级路径
        obj.path = parentPath + obj.path;
        // 第二步 判断有没有children属性 如有，那么需要再处理，如果没有则直接push到一个新数组中
        if (obj.children && obj.children.length > 0) {
          obj.children = this.resolve(obj.children, obj.path);
        }
        if (obj.meta.hidden) {
          if (obj.children && obj.children.length > 0) {
            obj.children.forEach((item) => {
              let tmp = Object.assign({}, item);
              newArr.push(tmp);
            });
          }
        } else {
          newArr.push(obj);
        }
      });

      return newArr;
    },
    handleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
  },
  computed: {
    menus() {
      let arr = this.resolve(routes);
      return arr;
    },
    asideStyle() {
      return {
        width: this.isCollapse ? "auto" : "200px",
      };
    },
    iconDeg() {
      return {
        "icon-deg": this.isCollapse ? true : "",
      };
    },
  },
};
</script>

<style scoped>
.el-header,
.el-footer {
  background-color: #707070;
  color: rgb(12, 12, 12);
  text-align: center;
  align-items: center;
  font-size: 14px;
      width: 100%;
}

.el-main {
  background-color: #707070;
  color: #333;
  text-align: center;
}
/* .el-container{
  width: 1440px;
} */
body > .el-container {
  background-color: #545c64 !important;
  margin: 0px !important;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 310px;
}
.el-header {
  background-color: #eeeeee;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.icon-deg {
  transform: rotate(-90deg);
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.el-aside{
  background-color:  rgb(84, 92, 100);
}
</style>